<script type='text/javascript' src='{sugar_getjspath file='include/javascript/sugar_grp_overlib.js'}'></script>
<div class="moduleTitle">
<h2><a href="index.php?module=edanz_Feedback&amp;action=index">{$MOD.LBL_MODULE_NAME}</a><span class="pointer">&raquo;</span>{$TITLE_PARAMS}</h2>
<span class="utils">&nbsp;
<a target="_blank" class="utilsLink" href="index.php?module=Administration&amp;action=SupportPortal&amp;view=documentation&amp;version=6.0.0&amp;edition=CE&amp;lang=en_us&amp;help_module=Opportunities&amp;help_action=EditView&amp;key=">
<img alt="Help" src="themes/Sugar5/images/help.gif?s=a4c566d9e802d5a3f4f57ca5364a3c68&amp;c=1&amp;developerMode=666782627"></a>
<a target="_blank" class="utilsLink" href="index.php?module=Administration&amp;action=SupportPortal&amp;view=documentation&amp;version=6.0.0&amp;edition=CE&amp;lang=en_us&amp;help_module=Opportunities&amp;help_action=EditView&amp;key=">
Help
</a></span></div>

<form  id="feedbackform" name="feedbackform" method="POST" enctype="multipart/form-data" action="index.php">
        <input type="hidden" name="module" value="edanz_Feedback">
        <input type="hidden" name="record" value="{$ID}">
        <input type="hidden" id="action" name="action">
        <input type="hidden" name="return_module" value="{$RETURN_MODULE}">
        <input type="hidden" name="return_id" value="{$RETURN_ID}">
        <input type="hidden" name="return_action" value="{$RETURN_ACTION}">
        <input type="hidden" name="deliverable_id" value="{$DELIVERABLE_ID}">

        <div id ='buttons'>
                <table width="100%" border="0" cellspacing="0" cellpadding="0" >
                        <tr>
                                <td align="left" width='30%'>
                                        <table border="0" cellspacing="0" cellpadding="0" ><tr>
                                                <td class='buttons' nowrap="nowrap">
                                                <div id="save_button_div">
                                                        <input id="feedback_submit_button" class="button" onclick="this.form.action.value='FeedbackConstructionSave'; return verify_data('EditView');"  accesKey="{$APP.LBL_SAVE_BUTTON_TITLE}" type="submit" name="button" value="{$APP.LBL_SAVE_BUTTON_LABEL}" >
                                                </div></td>
						<td><div id="cancel_button_div"><input id="feedback_cancel_button" title="{$APP.LBL_CANCEL_BUTTON_TITLE}" accessKey="{$APP.LBL_CANCEL_BUTTON_KEY}" class="button" onclick="this.form.action.value='{$RETURN_ACTION}'; this.form.module.value='{$RETURN_MODULE}'; this.form.record.value='{$RETURN_ID}';" type="submit" name="button" value="{$APP.LBL_CANCEL_BUTTON_LABEL}"></div></td>
                                                
                                        </tr></table>
                                </td>
                        </tr>
                </table>
        </div>
        <table class="edit view" width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                <td colspan="4">&nbsp;</td>
                </tr>
                <tr>
                <td width="17%" scope="row"><span sugar='slot1'>{$MOD.LBL_FEEDBACK_NUMBER}</span sugar='slot'></td>
                <td width="33%" ><span sugar='slot1b'>{$FEEDBACK_NUMBER}</span sugar='slot'></td>
                <td width="15%" scope="row">{$MOD.LBL_R2JOBNUMBER}<span sugar='slot2'></span sugar='slot'></td>
                <td width="35%" ><span sugar='slot2b'><input id='r2jobnumber_c' name='r2jobnumber_c' value="{$R2JOBNUMBER_C}" /></span sugar='slot'></td>
                </tr>
                <tr>

                <td width="17%" scope="row"><span sugar='slot3'>{$MOD.LBL_NAME} <span class="required">{$APP.LBL_REQUIRED_SYMBOL}</span></span sugar='slot'></td>
                <td width="33%" ><span sugar='slot3b'><select id='name' name='name' title='{$MOD.LBL_NAME}' tabindex='1'>{$NAME_OPTIONS}</span sugar='slot'>
                </td>
                <td width="15%" scope="row"><span sugar='slot4'>{$MOD.LBL_CC}</span sugar='slot'></td>
                <td width="35%" ><span sugar='slot4b'><input id='cc_c' name='cc_c' value="{$CC_C}" /></span sugar='slot'></td>
                </tr>
		<tr>
                <td width="17%" scope="row"><span sugar='slot5'>{$MOD.LBL_QUALITY_RATING} <span class="required">{$APP.LBL_REQUIRED_SYMBOL}</span></span sugar='slot'>{sugar_help text=$MOD.LBL_QUALITY_RATING_TEXT }</td>
                <td width="33%" ><span sugar='slot5b'>
			{foreach from=$QUALITY_RATINGS item=rating}
				<label><input id="quality_rating" type="radio" value="{$rating.numeric_rating}" name="quality_rating" {$rating.checked_string}>{$rating.description}</label><br>
			{/foreach}

</span sugar='slot'></td>
                <td width="15%" scope="row"><span sugar='slot6'></span sugar='slot'></td>
                <td width="35%" ><span sugar='slot6b'><table><tr><td><input id='r2jobname_c' name='r2jobname_c' value="{$R2JOBNAME_C}" type="hidden"/></td></tr>
<tr><td><input id='r2joburl_c' name='r2joburl_c' value="{$R2JOBURL_C}" type="hidden"/><p><a href="{$R2JOBURL_C}">{$R2JOBNAME_C}</a></p></td></tr></table>
</span sugar='slot'></td>
                </td>
                </tr>
                <tr>
                <td width="17%" scope="row"><span sugar='slot7'>{$MOD.LBL_RELATED_EDITOR_NAME} </span sugar='slot'></td>
                <td width="33%" ><span sugar='slot7b'><input class="sqsEnabled" tabindex="2" autocomplete="off" id="related_editor_name" name="related_editor_name"  title='{$APP.LBL_ASSIGNED_TO}' type="text" value="{$RELATED_EDITOR_NAME}"><input id='related_editor_id' name='related_editor_id' type="hidden" value="{$RELATED_EDITOR_ID}" />
					<input title="{$APP.LBL_SELECT_BUTTON_TITLE}" accessKey="{$APP.LBL_SELECT_BUTTON_KEY}" type="button" tabindex='2' class="button" value='{$APP.LBL_SELECT_BUTTON_LABEL}' name=btn1 onclick='open_popup("edanz_Editor", 600, 400, "", true, false, {$encoded_users_popup_request_data});' />
				</td>
                <td width="15%" scope="row"><span sugar='slot2'></span sugar='slot'></td>
                <td width="35%" ><span sugar='slot3b'></span sugar='slot'>
                </td>
                </tr>
                <tr>
                <td width="17%" scope="row"><span sugar='slot7'>{$MOD.LBL_ATTACHMENT} </span sugar='slot'></td>
                <td width="33%" ><span sugar='slot7b'>
                <input  id="attachment_c" name="attachment_c" type="file" ><BR>
                {if $ATTACHMENT != ''}
                <div id="upload_file">
                	<img align="absmiddle" onclick="deleteUploadFile();" style="cursor:pointer" src="index.php?entryPoint=getImage&themeName=Sugar5&imageName=minus.gif">
                	{$ATTACHMENT_NAME}
                </div>
                {/if}
                <input  name="uploaded_file_name" type="hidden" value="{$ATTACHMENT}">
                <input  id="isDelete" name="isDelete" type="hidden" value="0">
				</td>
                <td width="15%" scope="row"><span sugar='slot2'></span sugar='slot'></td>
                <td width="35%" ><span sugar='slot3b'></span sugar='slot'>
                </td>
                </tr>
	</table>

        <input type="hidden" id="existing_point_count" name="existing_point_count" value={$POINT_COUNT}>
        <input type="hidden" id="added_point_count" name="added_point_count" value=''>
        <input type="hidden" id="list_of_existing_points" name="list_of_existing_points" value="">
        <input type="hidden" id="list_of_points" name="list_of_points" value="">
        <input type="hidden" id="points_for_removal" name="points_for_removal" value="">



        <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
        <td ><h4>{$MOD.LBL_FEEDBACK_POINTS}</h4></td>
        </tr>
        </table>
        <table width = '100%' class='list view'>
		<tbody> <tr><td>
		<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td><input id="popup_feedback_point_category" name="popup_feedback_point_category" type='hidden'>
		<input id="popup_feedback_point_name" name="popup_feedback_point_name" type="hidden" value="">
		<input id="popup_feedback_point_description" name="popup_feedback_point_description" type="hidden" value="">
		<input id='popup_feedback_point_id' name='popup_feedback_point_id' title='List ID' type="hidden" value=''>
		<input title="{$MOD.LBL_SELECT_FEEDBACK_POINT}" type="button" tabindex='1' class="button" value='{$MOD.LBL_SELECT_FEEDBACK_POINT}' name=feedback_point_button id='feedback_point_button'
		onclick='open_popup("edanz_FeedbackPoint", 600, 400, "", false, false,  {$encoded_feedback_point_popup_request_data}, "single", true);'>
		</td>
		</tr>
	       <tr>

                                <th width='25%'><b>{$MOD.LBL_FEEDBACK_POINT_NAME}</b></th>
                            <th width='25%'><b>{$MOD.LBL_FEEDBACK_POINT_CATEGORY}</b></th>
                            <th><b>&nbsp;</b></th>
                    </tr>
		</table>
                        <div id='added_points'>
                                {$EXISTING_POINTS}
                        </div>
		</td></tr></tbody>
        </table>
        <table class="edit view" width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr><td colspan=4>&nbsp;</td></tr>
        <tr>
                <td width="17%" scope="row"><input title="{$MOD.LBL_GENERATE_FEEDBACK_TEXT}" type="button" class="button" value='{$MOD.LBL_GENERATE_FEEDBACK_TEXT}' name=generate_feedback_button id='generate_feedback_button'
        onclick='generate_feedback_text();'>
		</td>
                <td colspan=3 ><textarea id='description' name='description' title='{$MOD.LBL_DESCRIPTION}' cols="120" rows="6">{$DESCRIPTION}</textarea></td>
	</tr>
        </table>
        <div id ='buttons'>
                <table width="100%" border="0" cellspacing="0" cellpadding="0" >
                        <tr>
                                <td align="left" width='30%'>
                                        <table border="0" cellspacing="0" cellpadding="0" ><tr>
                                                <td class='buttons' nowrap="nowrap">
                                                <div id="save_button_div">
                                                        <input id="feedback_submit_button" class="button" onclick="this.form.action.value='FeedbackConstructionSave';"  accesKey="{$APP.LBL_SAVE_BUTTON_TITLE}" type="submit" name="button" value="{$APP.LBL_SAVE_BUTTON_LABEL}" >
                                                </div></td>
						<td><div id="cancel_button_div"><input id="feedback_cancel_button" title="{$APP.LBL_CANCEL_BUTTON_TITLE}" accessKey="{$APP.LBL_CANCEL_BUTTON_KEY}" class="button" onclick="this.form.action.value='{$RETURN_ACTION}'; this.form.module.value='{$RETURN_MODULE}'; this.form.record.value='{$RETURN_ID}';" type="submit" name="button" value="{$APP.LBL_CANCEL_BUTTON_LABEL}"></div></td>
                                                
                                        </tr></table>
                                </td>
                        </tr>
                </table>
        </div>

</form>


<script>
{literal}
function deleteUploadFile(){
	document.getElementById("upload_file").style.display="none";
	document.getElementById("isDelete").value = "1";
}
//create variables that will be used to monitor the number of feedback points 
var points_added = 0;
//variable that will be passed back to server to specify list of points
var list_of_points_array = new Array();

//this function adds selected point to list
function add_feedback_point(from_popup){

	//perform validation
	if(validate_feedback_point(from_popup)){
		POINTNAME = 'feedback_point_name';
		POINTID = 'feedback_point_id';
		POINTCATEGORY = 'feedback_point_category';
		POINTDESCRIPTION = 'feedback_point_description';

	if(from_popup == 'true'){
		POINTNAME = 'popup_feedback_point_name';
		POINTID = 'popup_feedback_point_id';
		POINTCATEGORY = 'popup_feedback_point_category';
		POINTDESCRIPTION = 'popup_feedback_point_description';
	}

		document.getElementById('added_point_count').value = points_added ;
		//get the appropriate values from feedback point form
		var point_name = document.getElementById(POINTNAME);
		var point_id = document.getElementById(POINTID);
		var point_category = document.getElementById(POINTCATEGORY);
		var point_category_text = point_category.value ;
		var point_description = document.getElementById(POINTDESCRIPTION);
		//construct html to display chosen tracker
		var point_name_html = "<input id='added_point_name"+points_added +"' type='hidden' size='20' maxlength='255' name='added_point_name"+points_added+"' value='"+point_name.value+"' >"+point_name.value;
		var point_id_html = "<input type='hidden' name='added_point_id"+points_added+"' id='added_point_id"+points_added+"' value='"+point_id.value+"' >";
		var point_category_html = "<input name='added_point_category"+points_added+"' id='added_point_category"+points_added+"' type='hidden' value='"+point_category.value+"'/>"+point_category_text;
		var point_description_html = "<input id='added_point_description"+points_added+"' type='hidden' name='added_point_description"+points_added+"' value='"+point_description.value+"' >";

		{/literal}
		//display the html
		var point_html = "<div id='point_added_"+points_added+"'> <table width='100%' class='tabDetailViewDL2'><tr class='tabDetailViewDL2' ><td width='25%'>"+point_name_html+"</td><td width='25%'>"+point_category_html+point_id_html+"</td>"+point_description_html+"<td>"+"<a href='#' onclick=\"remove_feedback_point('point_added_"+points_added+"','"+points_added+"'); \" >  <img src='{$REMOVE_IMAGE_PATH}' alt='rem' align='absmiddle' border='0' height='12' width='12'>{$MOD.LBL_REMOVE}</a></td></tr></table></div>";
		{literal}
		document.getElementById('added_points').innerHTML = document.getElementById('added_points').innerHTML + point_html;

		//add values to array in string, seperated by "@@" characters
		list_of_points_array[points_added] = point_id.value+"@@"+point_name.value+"@@"+point_category.value+"@@"+point_description.value;                  
		//assign array to hidden input, which will be used by server to process array of points
		//document.getElementById('list_of_points').value = list_of_points_array.toString();                         
		document.getElementById('list_of_points').value = list_of_points_array.join('||');                         

		//now lets clear the form to allow input of new point
		point_name.value = '';
		point_id.value = '';
		point_category.value = '';
		point_description.value = '';

	//increment point count value
		points_added++;

		if(points_added ==1){
			document.getElementById('no_points').style.display='none';
		}
	}
}


//this function will remove the selected  feedback point from the ui, and from the point array
function remove_feedback_point(div,num){
		//clear UI
		var point_div = document.getElementById(div);
		point_div.style.display = 'none';
		parentNE=point_div.parentNode;
		parentNE.removeChild(point_div);
		//clear point array from this entry and assign to form input
		list_of_points_array[num] = '';
		document.getElementById('list_of_points').value = list_of_points_array.join('||');                         
}

//this function will remove the existing feedback point from the ui, and add it's value to an array for removal upon save
function remove_existing_point(div,id){
		//clear UI
		var point_div = document.getElementById(div);
		point_div.style.display = 'none';
		parentNE=point_div.parentNode;
		parentNE.removeChild(point_div);
		//assign this id to form input for removal
		document.getElementById('points_for_removal').value += ','+id;
}



   /*
     * this is the custom validation script that will validate the fields
     * this is called directly from the add feedback point button
     */

function validate_feedback_point(from_popup){
	if(from_popup=='true'){
		return true;
	}
	else{
		return false;
	}
}


/*
*This function will populate values based on popup selection, and then call the
*function to add the entry to the list offeedback points 
*/
function set_return_feedback_point(popup_reply_data)
{
	var form_name = popup_reply_data.form_name;
	var name_to_value_array = popup_reply_data.name_to_value_array;

	for (var the_key in name_to_value_array)
	{
		if(the_key == 'toJSON')
		{
			/* just ignore */
		}
		else
		{
			window.document.forms[form_name].elements[the_key].value = name_to_value_array[the_key];
		}
	}
	add_feedback_point('true');
}

function generate_feedback_text(){

	var description = document.getElementById('description');
	{/literal}
	if(description.value == '' || confirm("{$MOD.FEEDBACK_OVERWRITE_WARNING}"))
	{literal}
	{
		var procedural_text = '';
		var editing_style_text = '';
		var commenting_style_text = '';
		var specific_points_text = '';
		var existing_point_count = document.getElementById("existing_point_count").value;
		for(var i=0; i<existing_point_count; i++){
			if(document.getElementById("existing_point" + i)){
				point_category = document.getElementById("existing_point_category" + i).value;
				point_name = document.getElementById("existing_point_name" + i).value;
				point_description = document.getElementById("existing_point_description" + i).value;
				
				switch(point_category){
				case "Procedural":
                                        procedural_text += point_name + "\n" + point_description + "\n\n";
                                        break;
				case "Editing Style":
					editing_style_text += point_name + "\n" + point_description + "\n\n";
					break;	
				case "Commenting Style":
					commenting_style_text += point_name + "\n" + point_description + "\n\n";
					break;
				case "Specific Comments":
					specific_points_text += point_name + "\n" + point_description + "\n\n";
					break;
				default:
					specific_points_text += point_name + "\n" + point_description + "\n\n";
				}
			}
		}

		for(var i=0; i<list_of_points_array.length; i++){
			if(list_of_points_array[i].length > 0){
				var feedbackpoint = list_of_points_array[i].split('@@');
				point_category = feedbackpoint[2]; 
				point_name = feedbackpoint[1]; 
				point_description = feedbackpoint[3]; 
				switch(point_category){
				case "Procedural":
                                        procedural_text += point_name + "\n" + point_description + "\n\n";
                                        break;
				case "Editing Style":
					editing_style_text += point_name + "\n" + point_description + "\n\n";
					break;
				case "Commenting Style":
					commenting_style_text += point_name + "\n" + point_description + "\n\n";
					break;
				case "Specific Comments":
					specific_points_text += point_name + "\n" + point_description + "\n\n";
					break;
				default:
					specific_points_text += point_name + "\n" + point_description + "\n\n";
                        	}
			}
		}

		var description_text = '';
		description_text += procedural_text;
		description_text += editing_style_text;
		description_text += commenting_style_text;
		description_text += specific_points_text;
		description.value = description_text.trim();
	}
}

function verify_data(form){
	if (document.getElementById("name").value == "") {
{/literal}
		alert('{$APP.ERR_MISSING_REQUIRED_FIELDS} {$MOD.LBL_NAME}' );
{literal}
		return false;
	}
	var radioButtons = document.getElementsByName("quality_rating");
	for (var x = 0; x < radioButtons.length; x ++) {
		if (radioButtons[x].checked) {
			return true;
		}
	}
{/literal}
	alert('{$APP.ERR_MISSING_REQUIRED_FIELDS} {$MOD.LBL_QUALITY_RATING}');
{literal}
	return false;
}
</script>
{/literal}
